from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 关注小区用例：case_004---反向用例

driver = webdriver.Edge(executable_path='D:\webdriver_驱动\msedgedriver.exe')
driver.maximize_window()
driver.get('https://bj.5i5j.com/')
# 隐式等待
driver.implicitly_wait(5)

sleep(3)
# 点击登录
driver.find_element(By.ID, 'home-login-btn').click()
sleep(2)
# 点击密码登录
driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div[3]/div[2]').click()
sleep(2)
# 显示等待***输入账号
sjh = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, '//*[@id="phone1"]'))
)
# 输入账号
sjh.send_keys('15985645480')
sleep(2)
# 输入密码
driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div[4]/div[3]/input').send_keys('gW09092434')
sleep(2)
# 点击立即登录
driver.find_element(By.ID, 'login-submit').click()
sleep(3)
# 点击用户信息（头像）
driver.find_element(By.ID, 'toUserCenter').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(3)
# 点击关注的小区
driver.find_element(By.XPATH, '//a[@href="/user/myfocus/3"]').click()
sleep(2)
# 点击关注更多小区
driver.find_element(By.CLASS_NAME, 'more-link').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(3)
# 点击要关注的小区
driver.find_element(By.XPATH, '/html/body/div[6]/div[1]/div[2]/ul/li[1]/div[1]/a/img').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(3)
# 点击关注（关注小区）
xq = driver.find_element(By.XPATH, '/html/body/div[5]/div[1]/div[2]/div[2]/a/span')
xq.click()
# 获取元素文本
print(f"元素文本：{xq.text}")
# 获取元素尺寸
print(f"元素尺寸-宽度：{xq.size['width']}, 高度：{xq.size['height']}")
# 获取元素坐标
print(f"元素坐标-x：{xq.location['x']}, y:{xq.location['y']}")
sleep(2)
# 点击关注（取消关注小区）
driver.find_element(By.XPATH, '/html/body/div[5]/div[1]/div[2]/div[2]/a/span').click()

sleep(10)







